home *** CD-ROM | disk | FTP | other *** search
/ Greatest Childrens Stories Ever Told / Greatest_Stories.iso / demos / funtown / demo.dir / 00054_Script_Scripts 12 < prev    next >
Text File  |  1994-11-08  |  10KB  |  170 lines

  1. --òòò Scripts 9
  2. -- òòò Will's ( development )
  3. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  4. -- The following handlers ( @, ?, !, activate, deactivate, store, restore, initTracking, exitTracking, writeData, writeTextFile, stringEntry ) are copyright ⌐ 1990-94 by W.D.Patrick and Cornell University and are used herein with permission.
  5. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  6. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  7. on @ spriteNum --ò provides the sprite location and center (USE CENTER WHEN locH&V ARE RETURNED AS NONSENSE VALUES.)
  8.   put "Sprite locH & locV: (" & the locH of sprite spriteNum& "," & the locV of sprite spriteNum & ").  Sprite center: (" &(the right of sprite spriteNum-the left of sprite spriteNum)/2+the left of sprite spriteNum & "," & (the bottom of sprite spriteNum-the top of sprite spriteNum)/2+the top of sprite spriteNum &")"
  9. end
  10.  
  11. on ? spriteNum --ò automates "activate" script writing. Place desired cast on stage in correct position
  12.   set theCast2=the castNum of sprite spriteNum
  13.   set theCast=string (numToChar(65+(theCast/64)))  &  ((theCast mod 64/8)+1)  &  (theCast mod 64 mod 8)
  14.   if the name of cast (theCast2)<>"0" then set theCast2=quote & the name of cast (theCast2) & quote
  15.   set putLine="Sprite: " & spriteNum & "   Cast: " & theCast2 & "   Type: " & the type of sprite spriteNum & "   Ink: " & the ink of sprite spriteNum 
  16.   set putLine=putLine& "   LocH,LocV: (" & the locH of sprite spriteNum & "," & the locV of sprite spriteNum & ")"
  17.   set putLine=putLine& "   Corners: (" & the left of sprite spriteNum & "," & the top of sprite spriteNum & "),(" & the right of sprite spriteNum & "," & the bottom of sprite spriteNum & ")"
  18.   set putLine=putLine& "   Stretch: " & the stretch of sprite spriteNum & "   Cursor: " & the cursor of sprite spriteNum
  19.   set putLine=putLine& return & return & "To activate [ spriteNum ] , copy this into your script:    "
  20.   set putLine2="activate [ spriteNum ] ," & theCast2 & "," & the type of sprite spriteNum & "," & the ink of sprite spriteNum & ","
  21.   if the stretch of sprite spriteNum=0 then set putLine2=putLine2& the locH of sprite spriteNum & "," & the locV of sprite spriteNum & "," & quote & quote & "," & quote & quote & "," & quote
  22.   else set putLine2=putLine2& the left of sprite spriteNum & "," & the top of sprite spriteNum & "," & quote &"stretch to:" "e& "," & the right of sprite spriteNum & "," & the bottom of sprite spriteNum & return
  23.   put putLine&putLine2
  24. end
  25.  
  26. on ! spriteNum --ò provides the cursor location. With the message window open and selected, place the cursor HotSpot over desired pixel. Type ! and return
  27.   if value(spriteNum)>0 then put "Cursor location, relative to the top left corner of sprite "&spriteNum&": (" & the mouseH-the left of sprite spriteNum & "," & the mouseV-the top of sprite spriteNum & ")."
  28.   else put "Cursor location: (" & the mouseH & "," & the mouseV & ")."
  29. end
  30.  
  31. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  32. --ò Activate / deactivate sprites ù Create puppetSprites with given dimensions/positions or return sprite control to the score
  33. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  34.  
  35. on activate spriteNum,targetCast,targetType,targetInk,targetH,targetV,stretchBool,targetH2,targetV2
  36.   puppetsprite spriteNum, true
  37.   set the type of sprite spriteNum=targetType
  38.   set the castNum of sprite spriteNum=the number of cast targetCast
  39.   set the ink of sprite spriteNum=targetink
  40.   set the foreColor of sprite spriteNum=255
  41.   set the backColor of sprite spriteNum=0
  42.   set the locH of sprite spriteNum=targetH
  43.   set the locV of sprite spriteNum=targetV
  44.   set the stretch of sprite spriteNum=(stretchBool<>"") --ò stretch=true if stretchBool is NOT empty
  45.   if stretchBool<>"" and targetH2<>"" then spritebox spriteNum,targetH,targetV,targetH2,targetV2
  46.   set the immediate of sprite spriteNum=true
  47. end
  48.  
  49. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  50. on deactivate spriteList
  51.   repeat with x=1 to the number of items in spriteList
  52.     set spriteNum=value ( item 1 of spriteList )
  53.     set the type of sprite spriteNum=0
  54.     puppetSprite spriteNum, false
  55.   end repeat
  56. end
  57.  
  58. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  59. --ò Store / restore sprites ù Create puppetSprites with given dimensions/positions or return sprite control to the score
  60. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  61. on store spriteList
  62.   set x=value ( item 1 of spriteList )
  63.   do ( "global type"&x& ", castNum"&x& ", ink"&x& ", foreColor"&x& ", backColor"&x& ", locH"&x& ", locV"&x )
  64.   do ( "set type"&x& "=the type of sprite x" )
  65.   do ( "set castNum"&x& "=the castNum of sprite x" )
  66.   do ( "set ink"&x& "=the ink of sprite x" )
  67.   do ( "set foreColor"&x& "=the foreColor of sprite x" )
  68.   do ( "set backColor"&x& "=the backColor of sprite x" )
  69.   do ( "set locH"&x& "=the locH of sprite x" )
  70.   do ( "set locV"&x& "=the locV of sprite x" )
  71.   if item 2 of spriteList<>"" then store ( item 2 to ( the number of items in spriteList ) of spriteList )
  72. end
  73.  
  74. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  75. on restore spriteList
  76.   set x=value ( item 1 of spriteList )
  77.   puppetsprite x, true
  78.   do ( "global type"&x& ", castNum"&x& ", ink"&x& ", foreColor"&x& ", backColor"&x& ", locH"&x& ", locV"&x )
  79.   do ( "set the type of sprite x=type"&x )
  80.   do ( "set the castNum of sprite x=castNum"&x )
  81.   do ( "set the ink of sprite x=ink"&x )
  82.   do ( "set the foreColor of sprite x=foreColor"&x )
  83.   do ( "set the backColor of sprite x=backColor"&x )
  84.   do ( "set the locH of sprite x=locH"&x )
  85.   do ( "set the locV of sprite x=locV"&x )
  86.   if item 2 of spriteList<>"" then restore ( item 2 to ( the number of items in spriteList ) of spriteList )
  87. end
  88.  
  89. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  90. --òòTracking Handlers: initTracking & exitTracking. ù All tracking devices throughout these scripts are denoted by "òò"
  91. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  92. on initTracking
  93.   global startTime
  94.   set startTime=the long time --ò store start time
  95.   if char 2 of startTime=":" then set startTime="0"&startTime --ò prepare startTime for HMS calculation.
  96.   set startTime=(value(char 1 to 2 of startTime)*60*60)+(value(char 4 to 5 of startTime)*60)+value(char 7 to 8 of startTime)
  97. end initTracking
  98.  
  99. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  100. on exitTracking
  101.   global startTime,endTime
  102.   writeData return&the long time&" Exited ""e&"simPharm""e 
  103.   set endTime=the long time --ò store exit time
  104.   if char 2 of endtime=":" then set endTime="0"&endTime --ò prepare endTime for HMS calculation.
  105.   set endTime=(value(char 1 to 2 of endtime)*60*60)+(value(char 4 to 5 of endtime)*60)+value(char 7 to 8 of endTime)
  106.   set hours="00"&string((endTime-startTime)/60/60) --ò calculate total time in program
  107.   set minutes="00"&string((endTime-startTime)/60 mod 60)
  108.   set seconds="00"&string((endTime-startTime) mod 60)
  109.   set hours=chars(hours,the number of chars in hours-1,the number of chars in hours) --ò truncate times to last 2 digits
  110.   set minutes=chars(minutes,the number of chars in minutes-1,the number of chars in minutes)
  111.   set seconds=chars(seconds,the number of chars in seconds-1,the number of chars in seconds)
  112.   return hours &":"&minutes&":"& seconds
  113. end exitTracking
  114.  
  115. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  116. --òòFile I/O: writeData, writeTextFile & stringEntry.
  117. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  118. on writeData theSource --ò Write tracking data to "userRecord". e.g., writeData the long time&" òExperiment: ""e&"Cut Parasympathetic Fiber""e
  119.   global theFile
  120.   
  121.   if theSource="" then  --ò Write user name to text file "userRecord"
  122.     if ((the text of cast "userName" contains "your full name") or (the text of cast "userName"="")) and not(the optionDown or the controlDown) then
  123.       beep2
  124.       set the text of cast "userName"="Please enter your full name."
  125.       exit
  126.     end if
  127.     writeTextFile --ò append file "userName"
  128.     theFile(mWriteString,"Tracking data for "&(chars(the text of cast "userName",1,31))&return&return)
  129.     theFile(mWriteString,the long time &"    Launched ""e&"simPharm""e&return)
  130.     set the selStart=0
  131.     set the selEnd=1000
  132.     setCursor 1,24,4 --ò set cursor to watch
  133.     go frame "ans" --ò advance to next phase
  134.     
  135.   else --ò theSource contains tracking data
  136.     writeTextFile --ò append file "userName"
  137.     theFile(mWriteString,string(theSource & return))
  138.   end if
  139.   
  140.   if objectP(theFile)<>0 then theFile(mdispose)
  141.   
  142. end writeData
  143.  
  144. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  145. on writeTextFile alertMessage --ò initializes text file "userRecord" (Places in same folder as MMDirector or Player)
  146.   global theFile,FileIO
  147.   set theFile=FileIO(mNew,"append",chars(the text of cast "userName",1,31)) --ò use initial 31 chars of userName
  148.   if not objectP(theFile) then --ò If error=-43, user has cancelled. Otherwise, alert
  149.     if theFile<>-43 then alert "File I/O object was not made."&return&"Error: "&string(theFile)&return&return&"Returning to Finder."
  150.     if voidP ( alertMessage ) then
  151.       set alertMessage="You have encountered an error."& return& "Please write down the number "& theFile& return& return& "Thank you."
  152.     end if
  153.     alert alertMessage
  154.     --ò quit --ò RETURN TO FINDER
  155.   end if
  156.   when keyDown then stringEntry
  157. end writeTextFile
  158.  
  159. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  160. on stringEntry --ò prevents user from typing return in text castmember. (return=clicking "OK.")
  161.   global userNameEntered
  162.   if userNameEntered<>"Please enter your full name." then exit --ò accept no more keyboard entries.
  163.   if the key<>Return then exit --ò continue updating userName.
  164.   set userNameEntered=the text of cast "userName"
  165.   dontPassEvent
  166.   updateStage
  167.   writeData "" --ò enter userName only
  168. end stringEntry
  169.  
  170. --ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù